<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>window对象</title>
    <!--setInterval,setTimeout-->
</head>
<body>

<span id="spn"></span>
<button onclick="fn1()">暂停</button>
<button onclick="fn1()">恢复</button>
</body>
<script>
    //每隔1秒调用
    var id = window.setInterval("showTime()",1000);
    //将当前时间显示到页面
    function showTime() {
        var currentTime = new Date();
        var spnEle = document.getElementById("spn");
        spnEle.innerHTML = currentTime;
    }

    /**
     * 暂停时间 :取消重复任务
     */
    function fn1(){
        window.clearInterval(id);
    }

    /**
     * 恢复时间,再次设置重复任务
     */
    function fn2(){
        id = window.setInterval("showTime()",1000);
    }
</script>
</html>